<?php
include_once($_SERVER['DOCUMENT_ROOT']."ExiaStore/Model/BDD.php");

class article {//création d'une class article
    private $idArticle;
    private $nomArticle;
    private $description;
    private $prix;
    private $etatArticle;
    private $categorie;
    private $auteur;
    private $editeur;
    private $dateEdition;
    private $bdd;
    private $photo;
    
    public function __construct($idarticle){//constructeur de la classe article
    $this->bdd = new BDD();
    $this->idArticle = $idarticle;
    $this->setNomArticle();
    $this->setDescription();
    $this->setPrix();
    $this->setEtatArticle();
    $this->setCategorie();
    $this->setAuteur();
    $this->setEditeur();
    $this->setDateEdition();
    $this->setPhoto();
    }
    
    private function setNomArticle(){//ajoute ou modifie un nom à un article
        $req = "SELECT article FROM article WHERE idArticle = $this->idArticle";
        $rslt = $this->bdd->getBDD()->query($req);
        $tab = $rslt->fetch(PDO::FETCH_ASSOC);
        $this->nomArticle = $tab['article']; 
       
    }
    
    private function setDescription(){//ajoute ou modifie une description à l'article
        $req = "SELECT description FROM article WHERE idArticle = $this->idArticle";
        $rslt = $this->bdd->getBDD()->query($req);
        $tab = $rslt->fetch(PDO::FETCH_ASSOC);
        $this->description = $tab['description'];       
    }
    
    private function setPrix(){//ajoute ou modifie un prix à l'article
        $req = "SELECT prix FROM article WHERE idArticle = $this->idArticle";
        $rslt = $this->bdd->getBDD()->query($req);
        $tab = $rslt->fetch(PDO::FETCH_ASSOC);
        $this->prix = $tab['prix'];       
    }
    
    private function setEtatArticle(){//ajoute ou modifie état de l'article 
        $req = "SELECT etatarticle FROM article WHERE idArticle = $this->idArticle";
        $rslt = $this->bdd->getBDD()->query($req);
        $tab = $rslt->fetch(PDO::FETCH_ASSOC);
        $this->etatArticle = $tab['etatarticle'];       
    }
    
    private function setCategorie(){//ajoute ou modifie la catégorie de l'article
        $req = "SELECT categorie FROM article WHERE idArticle = $this->idArticle";
        $rslt = $this->bdd->getBDD()->query($req);
        $tab = $rslt->fetch(PDO::FETCH_ASSOC);
        $this->categorie = $tab['categorie'];       
    }
    
    private function setAuteur(){//ajoute ou modife l'auteur de l'article
        $req = "SELECT auteur FROM article WHERE idArticle = $this->idArticle";
        $rslt = $this->bdd->getBDD()->query($req);
        $tab = $rslt->fetch(PDO::FETCH_ASSOC);
        $this->auteur = $tab['auteur'];       
    }
    
    private function setEditeur(){//ajoute ou modifie l'editeur de l'article 
        $req = "SELECT editeur FROM article WHERE idArticle = $this->idArticle";
        $rslt = $this->bdd->getBDD()->query($req);
        $tab = $rslt->fetch(PDO::FETCH_ASSOC);
        $this->editeur = $tab['editeur'];       
    }
    
    private function setDateEdition(){//ajoute ou modifie la date d'édition de l'article
        $req = "SELECT dateedition FROM article WHERE idArticle = $this->idArticle";
        $rslt = $this->bdd->getBDD()->query($req);
        $tab = $rslt->fetch(PDO::FETCH_ASSOC);
        $this->dateEdition = $tab['dateedition'];       
    }
    
    public function getNomArticle(){ 
        return $this->nomArticle;
    }
    
    public function getDescription(){
        return $this->description;
    }
    
    public function getPrix(){
        return $this->prix;
    }
    
    public function getAuteur(){
        return $this->auteur;
    }
    
    public function getEditeur(){
        return $this->editeur;
    }
    
    public function getEtatArticle(){
        return $this->etatArticle;
    }
    
    public function getCategorie(){
        return $this->categorie;
    }
    
    public function getIDArticle(){
        return $this->idArticle;
    }
    
    public function getDateEdition(){
        return $this->dateEdition;
    }
    
    public function getPhoto(){
        return $this->photo;
    }
    
    private function setPhoto(){
        $req = "SELECT photo FROM article WHERE idArticle = $this->idArticle";
        $rslt = $this->bdd->getBDD()->query($req);
        $tab = $rslt->fetch(PDO::FETCH_ASSOC);
        $this->photo = $tab['photo'];
    }
}

?>
